package logic

import (
	"context"
	"errors"
	"fmt"
	"house/model/mysql"

	"house/house"
	"house/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UsersListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUsersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UsersListLogic {
	return &UsersListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UsersListLogic) UsersList(in *house.UsersListRequest) (*house.UsersListResponse, error) {
	// todo: add your logic here and delete this line
	var s []mysql.Shop
	mysql.DB.Order("created_at desc").Find(&s)
	var usersList []*house.UsersList
	for _, k := range s {
		if k.Audit != int(in.Audit) {
			logx.Error("未审核")
			return nil, errors.New("未审核")
		}
		usersList = append(usersList, &house.UsersList{
			Title:  k.Title,
			Info:   k.Info,
			Price:  float32(k.Price),
			Num:    k.Num,
			Image:  k.Image,
			UserId: int64(k.UserId),
			Audit:  int64(k.Audit),
		})
	}

	fmt.Println("111", usersList)
	return &house.UsersListResponse{
		List: usersList,
	}, nil
}
